﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Validation;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;

namespace Gtkj.CMS.DAL
{
    public class DbContextFactory
    {
        /// <summary>
        /// 保证dbContext在线程中唯一
        /// </summary>
        /// <returns></returns>
        public static DbContext CreateDbContext()
        {
            DbContext dbContext = (DbContext)CallContext.GetData("dbcontext");
            if (dbContext == null)
            {
                dbContext = new Model.ComponentEntities();
                CallContext.SetData("dbcontext", dbContext);
            }
            return dbContext;
        }




        
    }
}